function love.load()
    canvas = love.graphics.newCanvas(800, 600)
 
    -- Rectangle is drawn to the canvas with the regular alpha blend mode.
    love.graphics.setCanvas(canvas)
        love.graphics.clear()
        love.graphics.setBlendMode("alpha")
        love.graphics.setColor(1, 0, 0, 0.5)
        love.graphics.rectangle('fill', 0, 0, 100, 100)
    love.graphics.setCanvas()
    local canvas1vs=false
end
 
function love.draw()
    -- very important!: reset color before drawing to canvas to have colors properly displayed
    -- see discussion here: https://love2d.org/forums/viewtopic.php?f=4&p=211418#p211418
    love.graphics.setColor(1, 1, 1, 1)
 
    -- The rectangle from the Canvas was already alpha blended.
    -- Use the premultiplied alpha blend mode when drawing the Canvas itself to prevent improper blending.
    love.graphics.setBlendMode("alpha", "premultiplied")
    love.graphics.draw(canvas)
    -- Observe the difference if the Canvas is drawn with the regular alpha blend mode instead.
    love.graphics.setBlendMode("alpha")
    love.graphics.draw(canvas, 100, 0)
 
    -- Rectangle is drawn directly to the screen with the regular alpha blend mode.
    love.graphics.setBlendMode("alpha")
    if canvas1vs == true then
          love.graphics.setColor(1, 0, 0)
          love.graphics.rectangle('fill', 200, 0, 100, 100)
    end
  --判断鼠标是否进入区域

  
end

function love.keypressed(key)
   if key == "a" then
      canvas1vs=true
   end
   if key == "b" then
      canvas1vs=false
   end
end

function love.mousepressed(x, y, button, istouch)
  local moux= love.mouse.getX( )
	local mouy=love.mouse.getY( )
	if moux>0 and moux <100 then
		if mouy>0 and mouy<100 then
			if love.mouse.isDown(1) then
         canvas1vs=not(canvas1vs)  
      end
		end
  end
end

